<template>
  <el-dialog
    :close-on-click-modal="false"
    title="批量审核"
    v-model="visible"
    align-center
    width="600px"
    destroy-on-close
  >
    <el-form>
      <el-form-item label="审核">
        <el-radio-group v-model="form.audit_result" class="ml-4">
          <el-radio :value="1">通过</el-radio>
          <el-radio :value="2">驳回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="驳回类型" v-if="form.audit_result === 2">
        <VSelect
          v-model="form.reject_type"
          placeholder="驳回类型"
          :options="options"
        />
      </el-form-item>
      <el-form-item label="驳回原因" v-if="form.audit_result === 2">
        <el-input
          v-model="form.audit_remark"
          type="textarea"
          :autosize="{ minRows: 5 }"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="handleClose(false)">取 消</el-button>
      <el-button type="primary" :loading="loading" @click="save"
      >确 定
      </el-button
      >
    </template>
  </el-dialog>
</template>
<script setup lang="jsx">
  import api from "../api";
  import {ElMessage} from "element-plus";
  import {resMessage} from "@/utils/res";

  const props = defineProps({
    options: {type: Array, default: () => []},
  });
  const emit = defineEmits(["success"]);
  // 打开弹窗
  const loading = ref(false);
  const visible = ref(false);
  const form = ref({audit_result: 1});
  const open = async (val) => {
    visible.value = true;
    form.value.i_ids = val;
  };
  const save = () => {
    loading.value = true;
    api
      .batch_audut(form.value)
      .then((res) => {
        resMessage({
          res,
          success: () => {
            ElMessage.success("操作成功");
            handleClose(true);
          },
        });
      })
      .finally(() => {
        loading.value = false;
      });
  };
  const handleClose = (refresh) => {
    form.value = {audit_result: 1};
    visible.value = false;
    if (refresh) emit("success");
  };
  defineExpose({open});
</script>
<style lang="scss" scoped></style>
